/**
 * 
 */
package com.antilia.infomaresme.pages;

import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

/**
 * @author Ernesto
 *
 */
@SuppressWarnings("serial")
public class EqualSizeModel implements IModel<String> {

	private IModel<String> model;
	
	private String cached;
	
	/**
	 * Constructor.
	 * @param model
	 */
	public EqualSizeModel(String model) {
		this(Model.of(model));
	}
	
	/**
	 * Constructor.
	 */
	public EqualSizeModel(IModel<String> model) {
		this.model = model;
	}
	
	public void detach() {
		model.detach();
	}
	public String getObject() {
		if(cached != null)
			return cached;
		String object = model.getObject();
		if(object.length()>= 25) {
			return (cached = object.substring(0, 16)+"...");
		} else if(object.length() < 25) {
			return cached = object;
		} 
		return cached = object;
	}
	
	public void setObject(String object) {
		throw new IllegalStateException("Method");
	}

}
